<template>
  <div class="adminHeaderBox" ref="box">
    <header ref="k">
      <div class="view">
            <img src="https://assets.codepen.io/2002878/bilibili-winter-view-1.jpg" class="morning" alt="">
            <img src="https://assets.codepen.io/2002878/bilibili-winter-view-2.jpg" class="afternoon" alt="">
            <video autoplay loop muted class="evening">
                <source src="https://assets.codepen.io/2002878/bilibili-winter-view-3.webm" type="video/webm" />
            </video>
            <img src="https://assets.codepen.io/2002878/bilibili-winter-view-3-snow.png" class="window-cover" alt="">
        </div>

        <div class="tree">
            <img src="https://assets.codepen.io/2002878/bilibili-winter-tree-1.png" class="morning" alt="">
            <img src="https://assets.codepen.io/2002878/bilibili-winter-tree-2.png" class="afternoon" alt="">
            <img src="https://assets.codepen.io/2002878/bilibili-winter-tree-3.png" class="evening" alt="">
        </div>
      <div class="back" ref="back"></div>
    </header>

    <div class="koko">
      <el-dropdown>
        <span class="el-dropdown-link">
          <el-avatar src="/10.jpg" :size="40"></el-avatar>
          <el-icon class="el-icon--right" color="white" :size="25">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<style scoped>
  .adminHeaderBox {
    padding: 0 50px;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
    height: 160px;
    width: 100vw;
  }

  .logos {
    width: 170px;
    height: 100px;

  }

  .koko{
    position: absolute;
    right: 100px;

  }
  .el-dropdown-link {
    display: flex;
    align-items: center;
    outline: none;
  }



  header {
    width: 100%;
    height: 160px;
    position: absolute;
    overflow: hidden;
    --percentage: 0.5;
    margin-left: -50px;
    overflow: hidden;
    z-index: -1;
  }

  header .view,
  header .tree {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .back {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
  }

  header img,
  header video {
    position: absolute;
    display: block;
    width: 120%;
    height: 100%;
    object-fit: cover;
  }

  header .morning {
    z-index: 20;
    opacity: calc(1 - (var(--percentage) - 0.25) / 0.25);
  }

  header .afternoon {
    z-index: 10;
    opacity: calc(1 - (var(--percentage) - 0.5) / 0.5);
  }

  header .view {
    transform: translatex(calc(var(--percentage) * 100px));
  }

  header .tree {
    transform: translatex(calc(var(--percentage) * 50px));
    filter: blur(3px);
  }

  header.atmi .view,
  header.atmi .tree {
    transition: none;
  }

  header .view,
  header .tree {
    transition: 2s all ease-in;
  }

  header .window-cover {
    opacity: calc((var(--percentage) - 0.9) / 0.1);
  }


</style>

<script>
  export default{
    mounted(){
        let box = this.$refs.box
        let header = this.$refs.k
        let backs = this.$refs.back
        let one = document.querySelectorAll(".morning")[0];
        let s;

        box.addEventListener('mouseenter',(e)=>{
            s=e.clientX;
            header.classList.add('atmi')
        })
        box.addEventListener('mouseleave',(e)=>{
            header.classList.remove('atmi');
            header.style.setProperty('--percentage',0.5)
        })
        box.addEventListener("mousemove",(e)=>{
            let p = (e.clientX - s)/window.outerWidth + 0.5;
            header.style.setProperty('--percentage',p)
        })

        const divs = ()=>{
            let divNum = Math.floor(Math.random()*80);
            for(let i = 0;i <divNum;i++){
                let width = Math.floor(Math.random()*backs.offsetWidth);
                let tops = Math.floor(Math.random()*100);
                let div = document.createElement('div');
                div.style.width='3px';
                div.style.height='3px';
                div.style.borderRadius = '50%';
                div.style.position = 'absolute';
                div.style.left = width +'px';   
                div.style.top = -tops +'px';   
                div.style.backgroundColor = 'white';
                div.style.zIndex= 200;
                backs.appendChild(div);
                let times = setInterval(()=>{
                    div.style.top = (div.style.top).slice(0,-2)-0 + 10 +'px';
                    if((div.style.top).slice(0,-2) >= backs.offsetHeight){
                        clearInterval(times);
                        backs.removeChild(div)
                    }
                },80);
            }
        }
        setInterval(divs,500);
    }
  }
</script>